/*
 * DAOFactory.java
 *
 * Created on June 16, 2007, 7:28 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package jhub.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author dbotelho
 */
public class DAOFactory {
    
    private static final String DB_DRIVER= "org.postgresql.Driver";
    
    public static String DB_URL;
    public static String DB_USER;
    public static String DB_PASS;
    
    private static Connection conn;
    
    // method to create Cloudscape connections
    private static Connection createConnection() throws ClassNotFoundException, SQLException {
        if(conn==null){
            Class.forName(DB_DRIVER);
            conn= DriverManager.getConnection(DB_URL,DB_USER, DB_PASS);
        }
        return conn;
    }
    
    public static UserDAO getUserDAO() throws ClassNotFoundException, SQLException{
        return new UserDAO(createConnection());
    }
    
    public static HubSessionDAO getHubSessionDAO() throws ClassNotFoundException, SQLException{
        return new HubSessionDAO(createConnection());
    }
    
    public static HubDAO getHubDAO() throws ClassNotFoundException, SQLException{
        return new HubDAO(createConnection());
    }
    
    public static BanListDAO getBanListDAO() throws ClassNotFoundException, SQLException{
        return new BanListDAO(createConnection());
    }
    
    public static UserSessionDAO getUserSessionDAO() throws ClassNotFoundException, SQLException{
        return new UserSessionDAO(createConnection());
    }
    
    public static MessageDAO getMessageDAO() throws ClassNotFoundException, SQLException{
        return new MessageDAO(createConnection());
    }
}
